package com.laurentiuspilca.ssia.services;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class NameService {


    ////使用#name来表示授权表达式中方法参数的值
    @PreAuthorize("#name == authentication.principal.username")
    public List<String> getSecretNames(String name) {
        Map<String,List<String>> secretNames = new HashMap<>();

        List<String> list1 = new ArrayList();
        list1.add("Energico");
        list1.add("Perfecto");
        List<String> list2 = new ArrayList();
        list2.add("Fantastico");

        secretNames.put("natalie",list1);
        secretNames.put("emma",list2);

        return secretNames.get(name);
    }
}
